<template>
    <section>
        <!--工具条-->
        <div class="searchgrid">
            <router-link :to="{path:'/stock/parentStockFinance/create'}">
                <input class="yl-input-button" value=" 新增 " type="button">
            </router-link>
            <div style="float: right;">
                <input v-model="post_data.search.account" style="width:120px;height:20px;"
                       value="" maxlength="10" type="text" placeholder="搜索:账户号">
                <input v-model="post_data.search.securities_trader" style="width:120px;height:20px;"
                       value="" maxlength="10" type="text" placeholder="搜索:交易证券">
              <input class="yl-input-button" value=" 查询 " type="button" v-on:click="search">
            </div>

        </div>

        <!--列表-->
        <el-table :data="forms.list"
                  highlight-current-row
                  v-loading="loading"
                  style="width: 100%;">

            <el-table-column prop="id" label="账户ID" show-overflow-tooltip></el-table-column>
            <el-table-column prop="account" label="账户号" show-overflow-tooltip></el-table-column>
            <el-table-column prop="password" label="账户登陆密码" show-overflow-tooltip></el-table-column>
            <el-table-column prop="communication_pw" label="账户通讯密码" show-overflow-tooltip></el-table-column>
            <el-table-column prop="financier_name" label="客户姓名" show-overflow-tooltip></el-table-column>
            <el-table-column prop="capital_id" label="所属资金池" show-overflow-tooltip></el-table-column>
            <el-table-column prop="total_in_capital" label="账户入金总额" show-overflow-tooltip></el-table-column>
            <el-table-column prop="securities_trader" label="交易证券" show-overflow-tooltip></el-table-column>
            <el-table-column prop="created_time" min-width="130" label="创建时间" show-overflow-tooltip></el-table-column>
            <el-table-column prop="current_total_capital" label="母账户总资金" show-overflow-tooltip></el-table-column>
            <el-table-column prop="securities_account_market_value" label="持仓市值" show-overflow-tooltip></el-table-column>
            <el-table-column prop="available_capital" label="可用余额" show-overflow-tooltip></el-table-column>
            <el-table-column prop="freezn_capital" label="冻结资金" show-overflow-tooltip></el-table-column>
            <el-table-column prop="securities_account_remain" label="证券账户余额" show-overflow-tooltip></el-table-column>
            <el-table-column prop="securities_account_available_remain" label="证券账户可用余额" show-overflow-tooltip min-width="100px"></el-table-column>

            <el-table-column label="操作">
                <template scope="scope">
                    <router-link :to="{path:'/stock/parentStockFinance/edit/'+scope.row.id}">
                    修改
                    </router-link>
                    <a href="javascript:void(0);" @click="openAdjustBalance(scope.row)">修改余额</a>
                </template>
            </el-table-column>
        </el-table>

        <!--工具条-->
        <div class="pagination">
        <el-col :span="24" class="toolbar">
            <el-pagination
                    @size-change="changeSize"
                    @current-change="pageChange"
                    :current-page="post_data.offset/post_data.limit+1"
                    :page-sizes="[15, 30, 45, 60]"
                    :page-size="post_data.limit"
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="forms.count"
                    style="float:left;">
            </el-pagination>
        </el-col>
        </div>

        <el-dialog
                title="修改余额"
                custom-class="width30"
                :visible.sync="dialogVisible"
                top="150px">
            <el-form :model="form1">
                <el-form-item label="母账户信息" label-width="200px">
                    账户号: {{form1.account}}
                    <br/>
                    客户姓名: {{form1.financier_name}}
                    <br/>
                    交易证券: {{form1.securities_trader}}
                </el-form-item>
                <el-form-item label="增减可用余额(增为正,减为负)" label-width="200px">
                    <el-input size="small" style="width:200px" v-model="form1.offset_amount" auto-complete="off"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button size="small" @click="dialogVisible = false">取 消</el-button>
                <el-button size="small" type="primary" @click="doAdjustBalance(form1)">确 定</el-button>
            </span>
        </el-dialog>
    </section>
</template>

<script>
    import {getParentStockFinances} from '../../../api/stock';
    import {adjustBalance} from '../../../api/java';

    export default {
        data() {
            return {
                loading: false,
                dialogVisible:false,
                forms:{},
                form1:{},
                post_data:{
                    field: ['id', 'account', 'password', 'communication_pw', 'financier_name', 'capital_id', 'total_in_capital',
                        'securities_trader', 'created_time', 'securities_account_market_value',
                        'available_capital', 'freezn_capital', 'securities_account_remain', 'securities_account_available_remain',
                        '0 as current_total_capital'],
                    search:{
                        account:'',
                        securities_trader:''
                    },
                    count:true,
                    offset:0,
                    limit: 15
                }
            }
        },
        created(){
            this.getList();
        },
        methods: {
            getList: function(){
                this.loading = true;
                getParentStockFinances(this.post_data).then(res => {
                    this.loading = false;
                    if (res.status === 0) return this.ezNotifyAxiosThen(res);
                    this.forms = res.data;
                }).catch(error => this.ezNotifyAxiosCatch(error));
            },
            pageChange: function (index) {
                this.post_data.offset = (index-1)*this.post_data.limit;
                this.getList();
            },
            changeSize: function (num) {
                this.post_data.offset = 0;
                this.post_data.limit = num;
                this.getList();
            },
            search: function () {
                this.post_data.offset = 0;
                this.getList();
            },
            openAdjustBalance: function (row) {
                this.dialogVisible = true;
                this.form1 = row;
            },
            doAdjustBalance: function (row) {
                this.$confirm('确认要修改余额吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.loading = true;
                    adjustBalance({parentStockFinanceId: row.id, offsetAmount: row.offset_amount}).then((res) => {
                        this.ezNotifyAxiosThen(res);
                        this.getList();
                        this.loading = false;
                        this.dialogVisible = false;
                    }).catch(error => console.log(error));
                }).catch(() => {
                });
            }
        }
    }
</script>

<style scoped>
</style>
